<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script type="text/javascript" src="js/global.js"></script>
		<script src="./layui/layui.js"></script>
	</head>

	<body>
		<div class="layui-form-item" style="margin-top: 20px">
			<label class="layui-form-label">学生姓名：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="stuName" id="stuName" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">年龄：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="age" id="age" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">性别：</label>
			<div class="layui-input-inline" style="width: 350px">
				<select class="layui-input" name="sex" id="sex" lay-verify="required">
					<option value="">--- 请选择 ---</option>
					<option value="男">男</option>
					<option value="女">女</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">联系电话：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="phone" id="phone" onblur="ckphone()" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">留言来源：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="msgSource" id="msgSource" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">来源地址：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="sourceUrl" id="sourceUrl" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">地址：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="address" id="address" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<!--<div class="layui-form-item">
				<label class="layui-form-label">录入人：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="text" name="netPusherId" id="netPusherId" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label">QQ：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="qq" id="qq" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">微信：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="weiXin" id="weiXin" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<!--<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="content" id="content" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">课程方向：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="learnFoward" id="learnFoward" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">记录：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="record" id="record" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">缴费金额：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="money" id="money" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">进班备注：</label>
			<div class="layui-input-inline" style="width: 350px">
				<input type="text" name="inClassContent" id="inClassContent" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>-->
		<div hidden="hidden" class="layui-form-item">
			<label class="layui-form-label">是否开启：</label>
			<div class="layui-input-inline" style="width: 350px">
				<select class="layui-input" name="isopens" id="isopens" lay-verify="required">
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-btn-container" style="text-align: center;">
				<button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
			</div>
		</div>

		<script>
			//Demo
			layui.use(['form'], function() {
				var form = layui.form;
				var $ = layui.jquery;
				//解决跨域
				$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
					options.xhrFields = {
						withCredentials: true
					}
				})

				function getopen() {
					$.getJSON(globalData.server + "./openClose/getAll", function(obj) {
						var option = "";
						for(i = 0; i < obj.data.length; i++) {
							option += "<option value='" + obj.data[i].isopens + "'>" + obj.data[i].isopens + "</option>";
						}
						$("#isopens").html(option);
					});
				}
				getopen();
				//监听提交
				form.on('submit(formDemo)', function(data) {
					//					var ids = [];
					//					$.ajax({
					//						type: "post",
					//						url: globalData.server + "netFollow/selectUser",
					//						dataType: "json",
					//						success: function(data1) {
					//							for(var i in data1) {
					//								ids.push(data1[i].askerId);
					//							}
					//							console.log(ids);
					//							//产生0-(arr.length-1)的整数值,也是数组的索引
					//							var index = Math.floor(Math.random() * ids.length);
					//							var rand = ids[index];
					//							console.log(rand);
					$.ajax({
						type: "post",
						url: globalData.server + './student/add?netPusherId=' + globalData.getUserName(),
						dataType: "json",
						data: {
							'isopens': $("#isopens").val(),
							'inClassContent': $("#inClassContent").val(),
							'money': $("#money").val(),
							'record': $("#record").val(),
							'learnFoward': $("#learnFoward").val(),
							'content': $("#content").val(),
							'weiXin': $("#weiXin").val(),
							'qq': $("#qq").val(),
							'address': $("#address").val(),
							'sourceUrl': $("#sourceUrl").val(),
							'msgSource': $("#msgSource").val(),
							'phone': $("#phone").val(),
							'sex': $("#sex").val(),
							'age': $("#age").val(),
							'stuName': $("#stuName").val(),
						},
						success: function(data) {
							if(data.count > 0) {
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭   
							}
						}
					});
					//						}
					//					});
				});
			});
			//手机号码失去焦点后的样式
			function ckphone() {
				var phone = document.getElementById("phone").value;
				//正则表达式
				var reg = /^([1][358][0-9][0-9]{8})|([1][4][37][0-9]{8})|([1][7][01367][0-9]{8})$/
				if(reg.test(phone) == true) {
					//表示通过验证
					return true;
				} else {
					layer.msg("手机号不合法", {
						icon: 6
					});
					//表示验证不通过
					return false;
				}
			}
		</script>
	</body>

</html>